package asteroids.model.programs.expressions.ComposedExpressions.UnaryExpressions;

import asteroids.model.SpaceObject;
import asteroids.model.programs.expressions.BasicExpression;
import asteroids.model.programs.expressions.Expression;
import asteroids.model.programs.expressions.BasicExpressions.DoubleLiteral;
import asteroids.model.programs.expressions.BasicExpressions.Entity;
import asteroids.model.programs.expressions.ComposedExpressions.UnaryExpression;
import asteroids.model.programs.types.Type;

public class GetY extends UnaryExpression {

	/**
	 * Initialize the GetY object
	 * 
	 * @param exp
	 * 			The operand of this expression
	 * @effect ...
	 * 			|super(exp, line, column)
	 */
	public GetY(Expression exp, int line, int column){
		super(exp, line, column);
	}
	
	/**
	 * Returns the symbol for this Expression, namely getY
	 * 
	 * @return ...
	 * 			| return "getY"
	 */
	public String getOperatorSymbol() {
		return "getY";
	}
	
	/**
	 * Returns the BasicExpression of type DoubleLiteral containing the Yposition of the referenced entity
	 * @return...
	 * 			|return (new DoubleLiteral(entity.getPositionY());
	 */
	@Override
	public BasicExpression getResult() {
		SpaceObject entity = ((Entity)getOperand().getResult()).getValue();
		BasicExpression result = new DoubleLiteral(entity.getPositionY(), getLine(), getColumn());
		return result;	
	}
	
	@Override
	public Type getType(){
		return Type.DOUBLE;
	}
	
	@Override
	public Type[] getOperandType(){
		return new Type[]{Type.ENTITY};
	}

}